#include "stdio.h"
#include "stdint.h"
#include "string.h"
#include "saeJ1939.h"
#include "GBT27930Pgn.h"
#include "GBT27930.h"


int8_t cGBT27930_PGN0100Fuction(void *pvHandle, int8_t cMode)
{
    J1939PackType *ptypeJ1939Pack = pvHandle;

    /* 发送 */
    if(cMode != 0)
    {
        ptypeJ1939Pack->P = 6;
        ptypeJ1939Pack->PGN = 0x000100;
        ptypeJ1939Pack->length = 8;

        /* BMS不能辨识:0x00; BMS能辨识:0xAA */
        ptypeJ1939Pack->datas[0] = 0xAA;

        /* 充电机编号, 1/位, 0 偏移量 */
        ptypeJ1939Pack->datas[1] = 0x00;
        ptypeJ1939Pack->datas[2] = 0x00;
        ptypeJ1939Pack->datas[3] = 0x00;
        ptypeJ1939Pack->datas[4] = 0x00;

        /* 充电机/充电站所在区域编码,标准ASCII码 */
        ptypeJ1939Pack->datas[5] = 0x01;
        ptypeJ1939Pack->datas[6] = 0x02;
        ptypeJ1939Pack->datas[7] = 0x03;
    }
    /* 接收 */
    else
    {
    }


    return 0;
}

int8_t cGBT27930_PGN0200Fuction(void *pvHandle, int8_t cMode)
{
    J1939PackType *ptypeJ1939Pack = pvHandle;

    /* 发送 */
    if(cMode != 0)
    {
        ptypeJ1939Pack->P = 7;
        ptypeJ1939Pack->PGN = 0x000200;
        ptypeJ1939Pack->length = 8;

        /* 通信协议版本号，本标准规定当前版本为V1.1 */
        ptypeJ1939Pack->datas[0] = 0x01;
        ptypeJ1939Pack->datas[1] = 0x01;
        ptypeJ1939Pack->datas[2] = 0x00;

        /* 电池类型，磷酸铁锂:0x03 */
        ptypeJ1939Pack->datas[3] = 0x03;

        /* 整车动力蓄电池系统额定容量/Ah，0.1Ah/位，0Ah偏移量 */
        ptypeJ1939Pack->datas[4] = 10000 >> 8;
        ptypeJ1939Pack->datas[5] = 10000 & 0xFF;

        /* 整车动力蓄电池系统额定总电压/V，0.1V/位，0V偏移量 */
        ptypeJ1939Pack->datas[6] = 50000 >> 8;
        ptypeJ1939Pack->datas[7] = 50000 & 0xFF;
    }

    return 0;
}

int8_t cGBT27930_PGN2600Fuction(void *pvHandle, int8_t cMode)
{
    J1939PackType *ptypeJ1939Pack = pvHandle;

    /* 发送 */
    if(cMode != 0)
    {
        ptypeJ1939Pack->P = 6;
        ptypeJ1939Pack->PGN = 0x002600;
        ptypeJ1939Pack->length = 3;

        /* 通信协议版本号，本标准规定当前版本为V1.1 */
        ptypeJ1939Pack->datas[0] = 0x01;
        ptypeJ1939Pack->datas[1] = 0x01;
        ptypeJ1939Pack->datas[2] = 0x00;
    }

    return 0;
}

int8_t cGBT27930_PGN2700Fuction(void *pvHandle, int8_t cMode)
{
    J1939PackType *ptypeJ1939Pack = pvHandle;

    /* 发送 */
    if(cMode != 0)
    {
        ptypeJ1939Pack->P = 6;
        ptypeJ1939Pack->PGN = 0x002700;
        ptypeJ1939Pack->length = 2;

        /* 最高允许充电总电压，数据分辨率:0.1V/位，0V 偏移量 */
        ptypeJ1939Pack->datas[0] = 50000 >> 8;
        ptypeJ1939Pack->datas[1] = 50000 & 0xFF;
    }

    return 0;
}

int8_t cGBT27930_PGNxFuctionInit(void)
{
    cJ1939PgnCreat(0x000100, cGBT27930_PGN0100Fuction);
    cJ1939PgnCreat(0x000200, cGBT27930_PGN0200Fuction);
    cJ1939PgnCreat(0x002600, cGBT27930_PGN2600Fuction);
    cJ1939PgnCreat(0x002700, cGBT27930_PGN2700Fuction);

    return 0;
}
